<div class="model_actions_toolbar">
    <?php $this->widget('backend.components.toolbar.MediaCategories'); ?>
</div>
<link rel="stylesheet" href="<?php echo Yii::app()->baseUrl; ?>/assets/backend/nyroModal/styles/nyroModal.css" type="text/css" media="screen" />
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl; ?>/assets/backend/nyroModal/js/jquery.nyroModal-1.5.5.pack.js"></script>
<div id="media_lists">
    <?php
echo CHtml::beginForm(array('media/delete'), 'post', array(
    'onSubmit' => "return fnOnSubmitDeleteConfirm('" . CHtml::encode(Yii::t('jsmsg', 'confirm_delete')) . '\',\'' . Yii::t('jsmsg', 'unselect_tips') . "');"
));
?>
<table border="0" width="100%" cellpadding="0" cellspacing="0" class="datas_grid">
    <thead>
        <tr>
            <th><input type="checkbox" id="checkallboxs_top" onclick="$('input[name=\'delete[]\']').attr('checked', this.checked);" /></th>
            <th><?php echo $sort->link('category_id'); ?></th>
            <th><?php echo $sort->link('file_name'); ?></th>
            <th><?php echo $sort->link('file_size'); ?></th>
            <th><?php echo $sort->link('file_extension'); ?></th>
            <th><?php echo $sort->link('created'); ?></th>
            <th><?php echo $sort->link('updated'); ?></th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td>
                <input type="checkbox" id="checkallboxs_bottom" onclick="$('input[name=\'delete[]\']').attr('checked', this.checked);" />
                <?php
//                echo CHtml::hiddenField('current_node', $current_node);
                echo CHtml::imageButton(Yii::app()->baseUrl . '/assets/backend/images/action_delete.png');
                ?>
            </td>
            <td colspan="7">
                <?php $this->widget('BackendPager', array('pages' => $pages,)); ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
        <?php foreach($models as $n => $model): ?>
        <tr class="<?php echo ($n % 2) ? 'even' : 'odd'; ?>">
            <td class="sn_and_checkbox">
                <input type="checkbox" name="delete[]" value="<?php echo $model->id; ?>">
                <?php echo sprintf("%02d", ++$n + $pages->getCurrentPage() * $pages->getPagesize()); ?>
            </td>
            <td id="category_name_<?php echo $model->id; ?>"><?php echo CHtml::encode($model->category->name); ?></td>
            <td><?php echo CHtml::encode($model->file_name); ?></td>
            <td><?php echo $model->fileSizeFormatKB; ?></td>
            <td><?php echo strtoupper($model->file_extension); ?></td>
            <td class="date"><?php echo date('Y-m-d', $model->created); ?></td>
            <td class="date"><?php echo $model->updatedFormatted; ?></td>
            <td class="action_one">
                <?php
                echo CHtml::link(CHtml::image(Yii::app()->baseUrl . '/assets/backend/images/btn_edit.png'),
                    array('update', 'id' => $model->id)
                    );
                ?>
                <span></span>
                <?php
                echo CHtml::link(CHtml::image(Yii::app()->baseUrl . '/assets/backend/images/btn_show.png'),
                    array('show', 'id' => $model->id), array('class' => 'nyroModal')
                    );
                ?>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php echo CHtml::endForm(); ?>
</div>

<style type="text/css">
    div.datasLoading {
	width: 100%;
        text-align: center;
	height: 150px;
        float: right;
	text-indent: -9999em;
        background-position: center center;
        background-repeat: no-repeat;
        opacity: 1;
        background-image: url(<?php echo Yii::app()->baseUrl; ?>/assets/backend/images/ajaxLoader.gif);
    }
    div.datasLoading * {
        opacity: .2em;
    }
</style>
<script type="text/javascript">
    function fnChangeCategory() {
//        alert($("#category_id").val());
        var ids = fnGetIds();
//        alert(ids);
        $.ajax({
            type: "POST",
            url: "<?php echo $this->createUrl('media/changeCategory') ?>",
            data: "target=" + $("#category_id").val() + "&ids=" + ids,
            beforeSend: function() {
                $("#media_lists > table").hide();
                $("#media_lists").addClass("datasLoading");
            },
            success: function(result){
                $("#media_lists > table").show();
                $("#media_lists").removeClass("datasLoading");
                if (parseInt(result) != 0) {
                    var ids_array = ids.split(",");
                    for (loop = 0; loop <= ids_array.length; loop++) {
                        $('#category_name_' + ids_array[loop]).html(result);
                    }
                }
            },
            error: function(msg) {
                alert(msg);
            }
        });
    }
    function fnGetIds() {
        var ids;
        $('input[name=\'delete[]\']').each(function(i){
            if ($(this).attr("checked")) {
                ids = ids + $(this).val() + ',';
            }
        });
        return ids.substring(9, ids.length - 1);
    }
    $(function() {
        $("table tr").mouseover(function() { $(this).addClass("over"); });
        $("table tr").mouseout(function() {$(this).removeClass("over"); });
    });
</script>